<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="租户名称">
              <a-input placeholder="请输入租户名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="租户编号">
              <a-input placeholder="请输入租户编号" v-model="queryParam.id"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="创建时间">
              <a-range-picker v-model="queryParam.createTime"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
                @change="onCreateTimeChange" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="default"
        :scroll="{x:true}"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <!-- <a-divider type="vertical" />
          <a @click="handleConfigure(record)">数据配置</a>
          <a-divider type="vertical" />
          <a @click="handleLimit(record)">数据限制</a>
          <a-divider type="vertical" />
          <a @click="handleOpen(record)">开启</a> -->
        </span>

      </a-table>
    </div>

    <tenant-modal ref="modalForm" @ok="modalFormOk"></tenant-modal>
    <tenant-dataConfig-modal ref="modalForm1" @ok="modalFormOk"></tenant-dataConfig-modal>
    <tenant-dataLimit-modal ref="modalForm2" @ok="modalFormOk"></tenant-dataLimit-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import TenantModal from './modules/TenantModal'
  import TenantDataConfigModal from './modules/TenantDataConfigModal'
  import TenantDataLimitModal from './modules/TenantDataLimitModal'
  import { filterObj } from '@/utils/util';

  export default {
    name: "TenantList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      TenantModal,TenantDataConfigModal,TenantDataLimitModal
    },
    data () {
      return {
        description: 'adad管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: (text, record, index) =>
              `${(this.ipagination.current - 1) * this.ipagination.pageSize +
                (index + 1)}` //序号分页后连续
          },
          {
            title:'租户名称',
            align:"center",
            dataIndex: 'name'
          },{
            title:'租户编号',
            align:"center",
            dataIndex: 'id'
          },
          {
            title:'开始时间',
            align:"center",
            dataIndex: 'beginDate'
          },
          {
            title:'结束时间',
            align:"center",
            dataIndex: 'endDate'
          },
          {
            title:'数据分发',
            align:"center",
            dataIndex: 'data1'
          },
          {
            title:'数据限制',
            align:"center",
            dataIndex: 'data2'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status_dictText'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
            width: 160,
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:200,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/sys/tenant/list",
          delete: "/sys/tenant/delete",
          deleteBatch: "/sys/tenant/deleteBatch"
        },
        dictOptions:{},
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
       getQueryParams(){
        //高级查询器
        let sqp = {}
        if(this.superQueryParams){
          sqp['superQueryParams']=encodeURI(this.superQueryParams)
          sqp['superQueryMatchType'] = this.superQueryMatchType
        }
        var param = Object.assign(sqp, this.queryParam, this.isorter ,this.filters);

        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        delete param.createTime; //范围参数不传递后台
        return filterObj(param);
      },
      initDictConfig(){
      },
      onCreateTimeChange(value, dateString) {
        console.log(dateString[0],dateString[1]);
        this.queryParam.beginDate=dateString[0];
        this.queryParam.beginDate=dateString[1];
      },
      //数据配置
      handleConfigure(record){
        this.$refs.modalForm1.edit(record);
        this.$refs.modalForm1.title = "数据配置";
        this.$refs.modalForm1.disableSubmit = false;
      },
      //数据限制
      handleLimit(record){
        this.$refs.modalForm2.edit(record);
        this.$refs.modalForm2.title = "数据限制";
        this.$refs.modalForm2.disableSubmit = false;
      },
      //开启冻结
      handleOpen(record){

      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>